package billing.i.sys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import billing.i.dao.map.UserMapping;
import billing.i.entity.User;

public class Test {
	
	void add(UserMapping mapping) {
		User user = null; 
		for (int i = 0; i < 10; i++) {
			char na= (char) (97 + i);
			char[] ca = {na,na,na,na};
			user =  new User();
			user.setUserName(new String(ca));
			int age = (int) ((Math.random()*100)%100);
			user.setAge(age);
			user.setSex((int)( Math.random()*10)%2 +1);
			mapping.addObject(user);
			//System.out.println(user.toString());
		}
		
	}
	void delId(UserMapping mapping) {
		int userId = 2;
		mapping.deleteObjectById(userId);
	}
	void selectById(UserMapping mapping) {
		int userId = 4;
		User user = mapping.selectObjectById(userId);
	//	System.out.println(user.toString());
	}
	
	public static void main(String[] args) {
		SqlSession session = Ibatis.getSession();
		UserMapping mapping = session.getMapper(UserMapping.class);
		Test test = new Test();
		
		//test.add(mapping);
		//test.delId(mapping);
		//test.selectById(mapping);
		test.selectList(mapping);
		
//		test.selectById(mapping);
//		test.updateObject(mapping);
	//	test.selectById(mapping);
		
	//	test.selectObjectByCond(mapping);
		
		session.commit();
		session.close();
	}
	void selectObjectByCond(UserMapping mapping) {
		Map<String,Object> params = new HashMap<String, Object>();
		params.put("userName", "bbbb");
		params.put("sex", 1);
		List<User> lst = mapping.selectObjectByCond(params);
//		for (User user : lst) {
//			System.out.println(user.toString());
//		}
	}
	void updateObject(UserMapping mapping) {
		User user =  new User();
		user.setUserId(4);
		user.setUserName("DDD");
		int age = (int) ((Math.random()*100)%100);
		user.setAge(age);
		user.setSex((int)( Math.random()*10)%2 +1);
		mapping.updateObject(user);
	}
	void selectList(UserMapping mapping) {
		List<User> lst = mapping.selectAllObjects();
		for (User user : lst) {
			System.out.println(user.toString());
		}
	}
	
}
